#ifndef _IO_DEVICE_H_
#define _IO_DEVICE_H_

#include <Arduino.h>
#include <ESP8266WiFi.h>

#define FLASH_PAGE_SIZE (0x1000)
#define SYSTEM_PAR_ADDR (0xF8 << 12)
#define NVM_START_ADDR 0xEB
#define NVM_RUNT 0
#define NVM_WORKT 1
#define NVM_STAS 2
#define NVM_LDNUM 3 //启动计时

struct nvm_data_str
{
    uint16_t start_sec; //存储flash起始块
    uint16_t offset;    //flash偏移量
    uint32_t value;     //值
};
void nvm_datainit(void);
void nvm_save(struct nvm_data_str *nvm_d);
void nvm_load(struct nvm_data_str *nvm_d);
extern struct nvm_data_str nvm_data[];


#define TYPE_REMOTE 0 //遥控器
#define TYPE_SWITCH 1 //开关
#define TYPE_RGB    2 //彩灯
#define TYPE_POWER  3 //彩灯

#define DEVTYPE TYPE_SWITCH
extern uint8_t devstas;

#if (DEVTYPE == TYPE_SWITCH)
const byte reset_pin = D3;
const byte pilot_pin = D4;
const byte blue_pin = D6;
const byte green_pin = D7;
const byte red_pin = D8;
const byte out_pin = D8;
#else
const byte reset_pin = D3;
const byte pilot_pin = D2;
const byte blue_pin = D6;
const byte green_pin = D7;
const byte red_pin = D8;
const byte out_pin = D8;
#endif

void DEV_Init(void);
void pilot_set(char stas,char c);
void DEV_Loop(void);
void nvm_save(struct nvm_data_str *nvm_d);
void nvm_load(struct nvm_data_str *nvm_d);
void nvm_datainit(void);
void system_param_save(void);
void system_param_load(void);
void out_set(char stas, char ch);//输出控制
void argb_set(uint32_t argb);
#define FLASH_ERASE_PAGE ESP.flashEraseSector
#define FLASH_WRITE ESP.flashWrite
#define FLASH_READ ESP.flashRead

#endif
